using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ExplosionObj : MonoBehaviour
{
    public Transform exPos;

    public float upper_force = 3.0f;
    public float radius = 5.0F;
    public float power = 10.0F;

    void Start()
    {
        target_obj.SetActive(false);
    }

    public GameObject target_obj;
    
    public void btn_explode()
    {
        // target_obj.SetActive(true);
        var new_obj = ObjectPool.instance.GetObj("test_explosion", prefab: target_obj, position: target_obj.transform.position);
        new_obj.SetActive(true);
        
        Vector3 explosionPos = exPos.position;
        Collider[] colliders = Physics.OverlapSphere(explosionPos, radius);
        foreach (Collider hit in colliders)
        {
            Rigidbody rb = hit.GetComponent<Rigidbody>();

            if (rb != null)
                rb.AddExplosionForce(power, explosionPos, radius, upper_force);
        }
    }
}
